//
//  ShopDetailsController.m
//  EasyToTesco2.0
//
//  Created by 杨森 on 16/6/14.
//  Copyright © 2016年 EasyToTesco. All rights reserved.
//

#import "ShopDetailsController.h"
#import "ConfirmOrderController.h"

#import "AddShopCarView.h"
#import "ShopFirstCell.h"
#import "ShopSecondCell.h"
#import "ShopThirdCell.h"

#import "StandardsView.h"
#import "ShopCarViewController.h"
#import "DOPScrollableActionSheet.h"
#import "LogInViewController.h"
#import "ProductInfo.h"
#import "ImageTxtDetailsController.h"
#import "inviteCodeModel.h"


static NSString* const EASY_THUMB_IMAGE = @"https://mobile.umeng.com/images/pic/home/social/img-1.png";
static NSString* const EASY_Text = @"作为丽水最大最专注“OTO商城”亿乐购物吧目前已发展成为业内第一大商场，为广大会员以及加盟商家提供了良好的服务平台，为进一步响应国家关于“大众创业，万众创新”的号召，亿乐购物吧利用自身强大的数据资源，在浙江全省开展招商加盟。！";
static NSString* const EASY_Title = @"亿乐go,给你想要的";
static NSString* const EASY_WebLink = @"http://www.ylgw8.com";


@interface ShopDetailsController ()<UMSocialShareMenuViewDelegate,AddShopCarViewDelegate,StandardsViewBtnDelegate,UITableViewDelegate,UITableViewDataSource>
{
    MBProgressHUD *progressHUD;
    XRCarouselView *_XrCarouselView;
    NSArray *_cycleArray;
    //区分加入购物车 立即购买
    BOOL _selectStuas;
    NSDictionary *_urlDict;
    
    //分享链接
    NSString *link;
    
    //判断规格是否为空
    NSString *_judgeColor;
    NSString *_judgeSize;
    NSString *_judgeFeilv;
    NSString *_judgeTaocan;
    NSString *_judgeModel;
    NSString *_judgeTaste;
    NSString *_judgeGuige;
    
    //有无样式
    BOOL _styleStats;
    //样式所选择价格
    NSString *_selectStylePrice;
}

@property(nonatomic,strong)UITableView *detailsView;
@property(nonatomic,strong)StandardsView*StandardsView;

@property(nonatomic,strong)NSDictionary *goodsDetailDict;
@property(nonatomic,strong)inviteCodeModel *inviteModel;
//尺码
@property(nonatomic,strong)NSArray *sizeArray;
//颜色
@property(nonatomic,strong)NSArray *colorArray;
/**
 *  费率
 */
@property(nonatomic,strong)NSArray *feilvArray;
/**
 *  口味
 */
@property(nonatomic,strong)NSArray *tasteArray;
/**
 *  套餐
 */
@property(nonatomic,strong)NSArray *taoCanArray;
/**
 *  型号
 */
@property(nonatomic,strong)NSArray *modelArray;
/**
 *  规格
 */
@property(nonatomic,strong)NSArray *guigeArray;
/**
 *  样式内容
 */
@property(nonatomic,strong)NSArray *ysContentArray;
/**
 *  样式价格
 */
@property(nonatomic,strong)NSArray *ysPriceArray;
/**
 *  样式名字
 */
@property(nonatomic,strong)NSArray *ysNameArray;

@end

@implementation ShopDetailsController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"商品详情";
    
    [self addViews];
    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem barButtonItemWithBackgroundImage:[UIImage imageNamed:@"shopCar"] highBackgroundImage:nil target:self action:@selector(pushShopCarDidClick) title:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(standardsStyleContent:) name:@"StandardsViewContentNotification" object:nil];
    
    if (!self.expand_sn.length) {
        self.expand_sn = @"0";
    }
    
    //获取用户sn
    [self getUserExpandSn];
    
    [self getMoreDetailsRequestData];
}

- (void)getUserExpandSn;
{
    if (!SN_IS_EXIST)return;

    NSArray *snArray = [[ExpandSnPlist shareExpandPlist] readAllData];
    
    NSString *proStr = nil;
    NSString *snStr = @"0";
    for (NSDictionary *snDict in snArray) {
        proStr = [snDict objectForKey:SN_PRODUCT_ID];
        if ([self.goodsId isEqualToString:proStr]) {
            snStr = [snDict objectForKey:SN_EXPAND_ID];
            NSLog(@"snStr:%@",snStr);
            self.expand_sn = snStr;
            break;
        }
    }

}

//push购物车
- (void)pushShopCarDidClick
{
    ShopCarViewController *ShopCarVC = [[ShopCarViewController alloc] init];
    ShopCarVC.isPushCar = YES;
    [self.navigationController pushForm:self.navigationController pushToAndHidden:ShopCarVC];
}


- (void)addViews
{
    
    UITableView *detailsView = [[UITableView alloc] initWithFrame:CGRectMake(0,0, WIDTH,HEIGHT-HEIGHT/12-64) style:UITableViewStylePlain];
    [self.view addSubview:detailsView];
    self.detailsView = detailsView;
    detailsView.delegate =self;
    detailsView.dataSource = self;
    detailsView.rowHeight = UITableViewAutomaticDimension;
    detailsView.estimatedRowHeight = 44;
    detailsView.backgroundColor = BACKGROUND_COLOR;
    
    //分割线
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0,HEIGHT/12*11-65, WIDTH, 1)];
    lineView.backgroundColor = [UIColor blackColor];
    lineView.alpha = 0.1;
    [self.view addSubview:lineView];
    //
    AddShopCarView *addView = [[AddShopCarView alloc] initWithFrame:CGRectMake(0,HEIGHT/12*11-64, WIDTH, HEIGHT/12)];
    [self.view addSubview:addView];
    addView.delegate= self;
    
}

#pragma mark >>>>>>获取id并请求数据
- (void)getMoreDetailsRequestData
{
    
    //菊花加载
    progressHUD = [MBProgressHUD loadingInformationToView];
    [self.view addSubview:progressHUD];

    @weakify(self);
    EASY_DISPATCH_GLOBAL_QUEUE_DEFAULT((^{
        
        @strongify(self);
        NSDictionary *params = @{@"id":self.goodsId,@"clear_cache":@"1"};
        [[NetWorkSharedTools sharedNetWorkTools] objectWithURLDict:params AndMenthodName:@"/api/goods/info" completeBlock:^(id object) {
            NSLog(@"%@",object);
            if (JudgeBackDataCode) {
                
                NSDictionary *goodsDetailDict = [object objectForKey:@"data"];
                self.goodsDetailDict = goodsDetailDict;
                
                //轮播
                _cycleArray = [[NSArray alloc] init];
                _cycleArray = goodsDetailDict[@"xiaotu"];
                
                //图片地址
                _urlDict = goodsDetailDict[@"picprex"];
                
                link = goodsDetailDict[@"link"];
#warning 商品规格如果为空 返回字符串类型"" 有数据返回类型数组
                //尺码
                if ([goodsDetailDict[@"chima"] isKindOfClass:[NSString class]]) {
                    _judgeSize = goodsDetailDict[@"chima"];
                }else{
                    _sizeArray = goodsDetailDict[@"chima"];
                }
                
                //颜色
                if ([goodsDetailDict[@"yanse"] isKindOfClass:[NSString class]]) {
                    _judgeColor = goodsDetailDict[@"yanse"];
                }else{
                    self.colorArray = goodsDetailDict[@"yanse"];
                }
                
                //口味
                if ([goodsDetailDict[@"kouwei"] isKindOfClass:[NSString class]]) {
                    _judgeTaste = goodsDetailDict[@"kouwei"];
                }else{
                    self.tasteArray = goodsDetailDict[@"kouwei"];
                }
                
                //套餐
                if ([goodsDetailDict[@"taocan"] isKindOfClass:[NSString class]]) {
                    _judgeTaocan = goodsDetailDict[@"taocan"];
                }else{
                    self.taoCanArray = goodsDetailDict[@"taocan"];
                }
                
                //型号
                if ([goodsDetailDict[@"xinghao"] isKindOfClass:[NSString class]]) {
                    _judgeModel = goodsDetailDict[@"xinghao"];
                }else{
                    self.modelArray = goodsDetailDict[@"xinghao"];
                }
                
                //规格
                if ([goodsDetailDict[@"guige"] isKindOfClass:[NSString class]]) {
                    _judgeGuige = goodsDetailDict[@"guige"];
                }else{
                    self.guigeArray = goodsDetailDict[@"guige"];
                }
                
                //费率
                if ([goodsDetailDict[@"feilv"] isKindOfClass:[NSString class]]) {
                    _judgeFeilv = goodsDetailDict[@"feilv"];
                }else{
                    _feilvArray = goodsDetailDict[@"feilv"];
                }
                
                // 样式
                _styleStats = [self.goodsDetailDict[@"ysjgfc"] integerValue];
                //1为有样式 0为无样式
                if (_styleStats) {
                    _ysContentArray = self.goodsDetailDict[@"yscontent"];
                    _ysPriceArray = self.goodsDetailDict[@"ysprice"];
                    _ysNameArray = self.goodsDetailDict[@"ysname"];
                }
                
                EASY_DISPATCH_MAIN_THREAD(^{
                    [progressHUD hide:YES];
                    [self.detailsView reloadData];
                    [progressHUD removeFromSuperViewOnHide];
                });
            }
        }];
    }));
}


#pragma mark 获取邀请码
- (void)getQRCodeDataRequest
{
    
    progressHUD = [MBProgressHUD show:self.view andMessage:@"获取邀请码"];
    [self.view addSubview:progressHUD];
    

    NSDictionary *params = @{@"username":USERNAME};
    @weakify(self);
    [[NetWorkSharedTools sharedNetWorkTools] objectWithURLDict:params AndMenthodName:@"/api/expand/userToken" completeBlock:^(id object) {
  
        @strongify(self);
        if (JudgeBackDataCode) {
            
            NSDictionary *tempDict = [object objectForKey:@"data"];
            self.inviteModel = [[inviteCodeModel alloc] initWithDictionary:tempDict error:nil];
        }
        [progressHUD hide:YES];
        [self UMSocialShareUIConfig];
    }];

}

#pragma mark>>>>>>>>>>>>>>>收藏
//点击收藏
- (void)collectionDelegateBtnDidClick:(UIButton *)button{
    
    //用户是否登录
    if (![JudgeUserLogInTool JudgeUserLonInStatus:self.view]) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"您尚未登录用户" message:nil preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *SettingAction = [UIAlertAction actionWithTitle:@"去登录" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            LogInViewController *accountVC = [[LogInViewController alloc] init];
            accountVC.JudgeLogInBack = NO;
            UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:accountVC];
            [self presentViewController:nav animated:YES completion:nil];
        }];
        [alert addAction:SettingAction];
        
        
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消"style:UIAlertActionStyleCancel handler:nil];
        [alert addAction:cancelAction];
        
        [self presentViewController:alert animated:YES completion:nil];
        return;
    }
    
    NSDictionary *params = @{@"id":[NSString stringWithFormat:@"%@",_goodsId],
                             @"type":[NSString stringWithFormat:@"%d",1],
                             @"username":[NSString stringWithFormat:@"%@",USERNAME],
                             };

    [[NetWorkSharedTools sharedNetWorkTools] objectWithURLDict:params AndMenthodName:@"/api/goods/addFavorite" completeBlock:^(id object) {
        NSLog(@"%@",object);
        
        if (JudgeBackDataCode) {
            
            MBProgressHUD *hud = [MBProgressHUD showMessage:@"收藏成功" toView:self.view dimBackground:NO AndCompleteBlock:nil];
            [self.view addSubview:hud];
            
            button.selected = false;
            
        }else{
            
            button.selected = YES;
        }
        
        
    }];
}


#pragma mark>>>>>>>>>>>>>>>分享
- (void)shareDelegateBtnDidClick
{
    //未登录 普通邀请链接  登录后 链接+用户sn
    if (JudgeLogInData) {
        [self getQRCodeDataRequest];
    }else{
        [self UMSocialShareUIConfig];
    }
}

- (void)UMSocialShareUIConfig{
   
    [UMSocialShareUIConfig shareInstance].shareTitleViewConfig.isShow = false;
    
    [UMSocialUIManager setPreDefinePlatforms:@[@(UMSocialPlatformType_QQ),
                                               @(UMSocialPlatformType_WechatSession),
                                               @(UMSocialPlatformType_WechatTimeLine),
                                               @(UMSocialPlatformType_WechatFavorite)
                                               ]];
    
    //设置分享面板的显示和隐藏的代理回调
    //    [UMSocialUIManager setShareMenuViewDelegate:self];
    
    [UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
        // 根据获取的platformType确定所选平台进行下一步操作
        NSLog(@"%zd",platformType);
        
        [self shareTypeNameWithType:platformType];
    }];
    
    
}

//分享类型
- (void)shareTypeNameWithType:(NSInteger)typeIndex
{
    switch (typeIndex) {
        case 4:
        {
            [self shareImageToPlatformType:UMSocialPlatformType_QQ];
        }
            break;
        case 1:
        {
             [self shareImageToPlatformType:UMSocialPlatformType_WechatSession];
        }
            break;
        case 2:
        {
             [self shareImageToPlatformType:UMSocialPlatformType_WechatTimeLine];
        }
            break;
        case 3:
        {
             [self shareImageToPlatformType:UMSocialPlatformType_WechatFavorite];
        }
            break;
       
        default:
            break;
    }
    
}

- (void)shareImageToPlatformType:(UMSocialPlatformType)platformType
{
    
    
    //创建分享消息对象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    //设置文本
    
    NSString *linkStr = nil;
    if (JudgeLogInData && self.inviteModel) {
        linkStr = [NSString stringWithFormat:@"%@/sn/%@",link,self.inviteModel.extends_sn];
    }else{
        linkStr = link;
    }
    messageObject.text = [NSString stringWithFormat:@"<亿乐go,给你想要的>%@,请打开链接:%@",self.goodsDetailDict[@"title"],linkStr];
    
    //调用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
        if (error) {
            NSLog(@"************Share fail with error %@*********",error);
        }else{
            NSLog(@"response data is %@",data);
        }
    }];
    
}



#pragma mark>>>>>>>>>>>>>>>加入购物车 立即购买
- (void)AddShopCarViewDidClick:(UIButton *)button
{
    
    //用户是否登录
    if (![JudgeUserLogInTool JudgeUserLonInStatus:self.view]) {
        
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"您尚未登录用户" message:nil preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *SettingAction = [UIAlertAction actionWithTitle:@"去登录" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            LogInViewController *accountVC = [[LogInViewController alloc] init];
            UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:accountVC];
            [self presentViewController:nav animated:YES completion:nil];
        }];
        [alert addAction:SettingAction];
        
        
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消"style:UIAlertActionStyleCancel handler:nil];
        [alert addAction:cancelAction];
        
        [self presentViewController:alert animated:YES completion:nil];
        
        return;
    }
    
    //    判断有无库存
    if (![self judeKucunAlertVIewShow]) {
        return;
    }
    
#warning //商品无规格无需弹框直接加入购物车或者直接购买  有规格则弹StandardsView
    [self judgeGoodsHaveOrWithOutStandard:button];
    
    //加入购物车
    if (button.tag == 2000) {
        
        _selectStuas = YES;
        
    }else{
        
        //立即购买-->确认订单
        _selectStuas = false;
    }
}

#pragma mark 商品无规格无需弹框直接加入购物车或者直接购买
- (void)judgeGoodsHaveOrWithOutStandard:(UIButton *)sender
{
    
    
    //判断有无规格
    if (_judgeSize && _judgeColor && _judgeGuige && _judgeFeilv && _judgeModel && _judgeTaste &&_judgeTaocan && !_styleStats) {
        
        if (sender.tag == 2000) {
            //购物车
            NSDictionary *params = @{@"pid":[NSString stringWithFormat:@"%@",_goodsId],
                                     @"username":[NSString stringWithFormat:@"%@",USERNAME],
                                     @"num":@"1",
                                     @"sn":self.expand_sn
                                     };
            NSLog(@"---------%@",params);
            [[NetWorkSharedTools sharedNetWorkTools] objectWithURLDict:params AndMenthodName:@"/api/Cart/add" completeBlock:^(id object) {
                
                NSLog(@"%@",object);
                if (JudgeBackDataCode) {
                    MBProgressHUD *hud = [MBProgressHUD showMessage:@"亲~快去购物车结算吧!" toView:self.view dimBackground:NO AndCompleteBlock:nil];
                    [self.view addSubview:hud];
                }else{
                    
                    NSDictionary *dict = [object objectForKey:@"message"];
                    MBProgressHUD *hud = [MBProgressHUD showMessage:[NSString stringWithFormat:@"%@",dict[@"view"]] toView:self.view dimBackground:NO AndCompleteBlock:nil];
                    [self.view addSubview:hud];
                }
                
            }];
            
            
        }else{
            //直接购买
            NSLog(@"立即购买");
            NSDictionary *params = @{@"pid":[NSString stringWithFormat:@"%@",_goodsId],
                                     @"num":@"1",
                                     @"picprex":self.goodsDetailDict[@"picprex"],
                                     @"picurl":self.goodsDetailDict[@"picurl"],
                                     @"huiyuanjia":self.goodsDetailDict [@"huiyuanjia"],
                                     @"title":self.goodsDetailDict[@"title"],
                                     @"jzh":self.goodsDetailDict[@"jzh"],
                                     @"sn":self.expand_sn
                                     };
            
            
            ConfirmOrderController *ConfirmOrderVC = [[ConfirmOrderController alloc] init];
            ConfirmOrderVC.pruductDict = [NSMutableDictionary dictionaryWithDictionary:params];
            ConfirmOrderVC.judgeStandard = YES;
            ConfirmOrderVC.allPrice = [NSString stringWithFormat:@"%zd",[self.goodsDetailDict [@"huiyuanjia"] integerValue] * 1];
            ConfirmOrderVC.limitString = self.goodsDetailDict[@"limit_buy"];
            [self.navigationController pushForm:self.navigationController pushToAndHidden:ConfirmOrderVC];
            
        }
        
    }else{
        //有规格弹出
        [self buildStandardsView];
        
    }
}

//点击X或者透明消失
-(void)StandardsViewCancleBtnDidMiss:(UIButton *)button
{
    [_StandardsView dismissStandardsView];
}

#pragma mark 规格选择点击确定(有规格)
- (void)StandardsViewConfirmBtnClick:(UIButton *)button sizeStr:(NSString *)sizeStr colorStr:(NSString *)colorStr num:(NSString *)numStr tasteStr:(NSString *)tasteStr taocanStr:(NSString *)taocanStr modelStr:(NSString *)modelStr guigeStr:(NSString *)guigeStr feilvStr:(NSString *)feilvStr ysContentStr:(NSString *)ysContentStr
{
    [_StandardsView dismissStandardsView];
    if (_selectStuas) {
        
        NSLog(@"加入购物车");
        [self addShoppingCartNetworkRequestsSizeStr:sizeStr colorStr:colorStr num:numStr tasteStr:tasteStr taocanStr:taocanStr modelStr:modelStr guigeStr:guigeStr feilvStr:feilvStr ysContentStr:ysContentStr];
        
        
    }else{
        
        NSLog(@"立即购买");
        NSDictionary *params = @{@"pid":[NSString stringWithFormat:@"%@",_goodsId],
                                 @"num":numStr,
                                 @"picprex":self.goodsDetailDict[@"picprex"],
                                 @"picurl":self.goodsDetailDict[@"picurl"],
                                 @"huiyuanjia":self.goodsDetailDict [@"huiyuanjia"],
                                 @"jzh":self.goodsDetailDict[@"jzh"],
                                 @"尺码":[NSString stringWithFormat:@"%@",sizeStr],
                                 @"颜色":[NSString stringWithFormat:@"%@",colorStr],
                                 @"口味":[NSString stringWithFormat:@"%@",tasteStr],
                                 @"套餐":[NSString stringWithFormat:@"%@",taocanStr],
                                 @"型号":[NSString stringWithFormat:@"%@",modelStr],
                                 @"规格":[NSString stringWithFormat:@"%@",guigeStr],
                                 @"title":self.goodsDetailDict[@"title"],
                                 @"样式":[NSString stringWithFormat:@"%@",ysContentStr],
                                 @"sn":self.expand_sn
                                 };
        
        
        
        ConfirmOrderController *ConfirmOrderVC = [[ConfirmOrderController alloc] init];
        
        //有样式情况下 取样式所选择价格
        if (_styleStats) {
            NSMutableDictionary *styleParam = [NSMutableDictionary dictionaryWithDictionary:params];
            [styleParam setValue:_selectStylePrice forKey:@"huiyuanjia"];
            
            //样式名如果和字典里的某规格名冲突
            NSEnumerator * key = [styleParam keyEnumerator];
            for (NSObject *object in key) {
                if ([[NSString stringWithFormat:@"%@",_ysNameArray[0]] isEqual:object]) {
                    ConfirmOrderVC.judgeYsName = YES;
                }
            }
            
            ConfirmOrderVC.pruductDict = styleParam;
            //添加所选样式的规格
            [styleParam setObject:ysContentStr forKey:[NSString stringWithFormat:@"%@",_ysNameArray[0]]];
            ConfirmOrderVC.ysSelectName = [NSString stringWithFormat:@"%@",_ysNameArray[0]];
            ConfirmOrderVC.allPrice = [NSString stringWithFormat:@"%zd",[_selectStylePrice integerValue] * [numStr integerValue]];
        }else{
            ConfirmOrderVC.pruductDict = [NSMutableDictionary dictionaryWithDictionary:params];
            ConfirmOrderVC.allPrice = [NSString stringWithFormat:@"%zd",[self.goodsDetailDict [@"huiyuanjia"] integerValue] * [numStr integerValue]];
        }
        ConfirmOrderVC.limitString = self.goodsDetailDict[@"limit_buy"];
        [self.navigationController pushForm:self.navigationController pushToAndHidden:ConfirmOrderVC];
    }
    
}

/**
 *  商品添加到购物车
 */
- (void)addShoppingCartNetworkRequestsSizeStr:(NSString *)sizeStr colorStr:(NSString *)colorStr num:(NSString *)numStr tasteStr:(NSString *)tasteStr taocanStr:(NSString *)taocanStr modelStr:(NSString *)modelStr guigeStr:(NSString *)guigeStr feilvStr:(NSString *)feilvStr ysContentStr:(NSString *)ysContentStr
{
    
    NSDictionary *params = @{@"pid":[NSString stringWithFormat:@"%@",_goodsId],
                             @"username":[NSString stringWithFormat:@"%@",USERNAME],
                             @"chima":[NSString stringWithFormat:@"%@",sizeStr],
                             @"yanse":[NSString stringWithFormat:@"%@",colorStr],
                             @"kouwei":[NSString stringWithFormat:@"%@",tasteStr],
                             @"taocan":[NSString stringWithFormat:@"%@",taocanStr],
                             @"xinghao":[NSString stringWithFormat:@"%@",modelStr],
                             @"guige":[NSString stringWithFormat:@"%@",guigeStr],
                             @"num":[NSString stringWithFormat:@"%@",numStr],
                             @"feilv":[NSString stringWithFormat:@"%@",feilvStr],
                             @"yscontent":[NSString stringWithFormat:@"%@",ysContentStr],
                             @"sn":self.expand_sn
                             };
    NSLog(@"%@",params);
    [[NetWorkSharedTools sharedNetWorkTools] objectWithURLDict:params AndMenthodName:@"/api/Cart/add" completeBlock:^(id object) {
        
        NSLog(@"%@",object);
        if (JudgeBackDataCode) {
            MBProgressHUD *hud = [MBProgressHUD showMessage:@"亲~快去购物车结算吧!" toView:self.view dimBackground:NO AndCompleteBlock:nil];
            [self.view addSubview:hud];
        }else{
            
            NSDictionary *dict = [object objectForKey:@"message"];
            MBProgressHUD *hud = [MBProgressHUD showMessage:[NSString stringWithFormat:@"%@",dict[@"view"]] toView:self.view dimBackground:NO AndCompleteBlock:nil];
            [self.view addSubview:hud];
        }
        
    }];
    
}

#pragma mark 样式价格显示
- (void)standardsStyleContent:(NSNotification *)notification
{
    NSInteger index = [notification.userInfo[@"index"] integerValue];
    //    NSLog(@"------------------%zd",index);
    //    NSLog(@"%@",_ysPriceArray[index]);
    _selectStylePrice = _ysPriceArray[index];
    self.StandardsView.saleLabel.text = [NSString stringWithFormat:@"¥ %@",_ysPriceArray[index]];
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

#pragma mark >>>>>>>>>> 商品规格
- (void)buildStandardsView
{
    self.StandardsView = [[StandardsView alloc] initWithFrame:CGRectMake(0,0,WIDTH, HEIGHT)];
    self.StandardsView.delegate = self;
    
#warning 判断有无规格
    if (!_judgeColor) {
        _StandardsView.colorArray = _colorArray;
    }
    
    if (!_judgeSize) {
        _StandardsView.sizeArray = _sizeArray;
    }
    
    if (!_judgeTaste) {
        _StandardsView.tasteArray = _tasteArray;
    }
    
    if (!_judgeTaocan) {
        _StandardsView.taoCanArray = _taoCanArray;
    }
    
    if (!_judgeModel) {
        _StandardsView.modelArray = _modelArray;
    }
    
    if (!_judgeGuige) {
        _StandardsView.guigeArray = _guigeArray;
    }
    
    if (!_judgeFeilv) {
        _StandardsView.feilvArray = _feilvArray;
    }
    
    //样式
    if (_styleStats) {
        _StandardsView.ysNameArray = _ysNameArray;
        _StandardsView.ysContentArray = _ysContentArray;
        _StandardsView.ysPriceArray = _ysPriceArray;
    }
    
    //name
    _StandardsView.nameLabel.text = [NSString stringWithFormat:@"%@",self.goodsDetailDict[@"title"]];
    //价格
    _StandardsView.saleLabel.text = [NSString stringWithFormat:@"¥ %@",self.goodsDetailDict[@"huiyuanjia"]];
    
    //图片
    NSString *string = [NSString stringWithFormat:@"%@%@",_urlDict[@"m"],_goodsDetailDict[@"picurl"]];
    [_StandardsView.goodsImg  sd_setImageWithURL:[NSURL URLWithString:string] placeholderImage:[UIImage imageNamed:@"businessNopict.jpg"]];
    
    //规格show
    [_StandardsView showStandardsView];
}

//判断有无库存
- (BOOL)judeKucunAlertVIewShow
{
    //判断is_kucun 0代表无库存 1为有库存
    if ([_goodsDetailDict[@"is_kucun"] isEqual:@(0)]) {
        
        //弹框
        MBProgressHUD *hud = [MBProgressHUD showMessage:@"此商品已下架" toView:self.view dimBackground:NO AndCompleteBlock:nil];
        [hud show:YES];
        
        return NO;
        
    }else{
        
        return YES;
    }
    
}

#pragma mark>>>>>>>>数据源方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    //0 为无优惠活动
    if ([self.goodsDetailDict[@"is_show_inter_money"] isEqual:@(0)]) {
        
        if (section ==0 || section == 2) {
            return 0;
        }else if(section == 3){
            return 2;
        }else{
            return 1;
        }
        
    }else{
        
        if (section == 0) {
            return 0;
        }else if(section == 3){
            return 2;
        }else{
            return 1;
        }
        
    }
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section ==0) {
        return nil;
    }else if (indexPath.section ==1){
        
        ShopFirstCell *cell= [[ShopFirstCell alloc] init];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        if ([self.goodsDetailDict.allKeys count] > 0) {
            cell.nameLabel.text = self.goodsDetailDict[@"title"];
            cell.brandLabel.text = [NSString stringWithFormat:@"品牌:%@",self.goodsDetailDict[@"pinpai"]];
            cell.saleLabel.text = [NSString stringWithFormat:@"¥%@",self.goodsDetailDict [@"huiyuanjia"]];
            cell.totalLabel.text = [NSString stringWithFormat:@"¥%@",self.goodsDetailDict [@"shichangjia"]];
            
            if ([self.goodsDetailDict[@"jzh"] isEqual:@(0)]) {
                cell.postMoney.text = @"包邮";
            }else{
                cell.postMoney.text = [NSString stringWithFormat:@"邮费 : %@",self.goodsDetailDict[@"jzh"]];
            }
            
            
            //判断is_kucun 0代表无库存 1为有库存
            if ([_goodsDetailDict[@"is_kucun"] isEqual:@(0)]) {
                cell.kucun = [NSString stringWithFormat:@"%@",self.goodsDetailDict[@"kucun"]];
            }else{
                cell.kucun = [NSString stringWithFormat:@"库存%@件",self.goodsDetailDict[@"kucun"]];
            }
            
            cell.sale = [NSString stringWithFormat:@"销量 %@件",self.goodsDetailDict[@"sales"]];
            
            //limit_buy判断商品类型
            if ([self.goodsDetailDict[@"limit_buy"] isEqual:@(0)]) {
                cell.limit_buy = @"普通商品";
            }else if ([self.goodsDetailDict[@"limit_buy"] isEqual:@(1)]){
                cell.limit_buy = @"现金商品";
            }else{
                cell.limit_buy = @"代金券商品";
            }
            
        }
        return cell;
        
    }else if(indexPath.section ==2){
        
        //0 为无优惠活动
        if ([self.goodsDetailDict[@"is_show_inter_money"] isEqual:@(0)]) {
            return nil;
            
        }else{
            
            static NSString *servicesIdentifier= @"ServicesIdentifier";
            
            UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:servicesIdentifier];
            
            if (cell==nil) {
                cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:servicesIdentifier];
                
            }
            
            cell.imageView.image = [UIImage imageNamed:@"icon_services"];
            
            //优惠活动
            int money = [self.goodsDetailDict[@"give_money"] intValue];
            int integral = [self.goodsDetailDict[@"give_integral"] intValue];
            
            if (money != 0 && integral == 0) {
                cell.textLabel.text = [NSString stringWithFormat:@"累计赠送%zd代金券",money];
            }else if (money != 0 && integral != 0){
                cell.textLabel.text = [NSString stringWithFormat:@"    赠送%zd代金券   |   累计赠送%zd代金券",integral,money];
            }else if(money == 0 && integral != 0) {
                cell.textLabel.text = [NSString stringWithFormat:@"赠送%zd积分",integral];
            }else{
                cell.textLabel.text = @"无活动";
            }
            
            
            cell.textLabel.font = FONT(13);
            cell.textLabel.font = [UIFont boldSystemFontOfSize:13];
            cell.textLabel.textColor = DEFAULT_COLOR;
            
            return cell;
        }
        
        
    }else{
        
        ShopSecondCell *cell = [ShopSecondCell loadShopSecondCellView];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        if (indexPath.row == 0) {
            cell.commentLabel.text = @"图文详情";
            cell.commentLabel.font = [UIFont systemFontOfSize:13];
            cell.moreLabel.hidden = YES;
            return cell;
            
            
        }else{
            cell.commentLabel.text = @"商品评论";
            cell.commentLabel.font = [UIFont systemFontOfSize:13];
            return cell;
        }
        
    }
    
}

#pragma mark>>>>>>>>代理方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.section == 3 && indexPath.row == 0) {
        
        ImageTxtDetailsController *ImageTxtVC = [[ImageTxtDetailsController alloc] init];
        ImageTxtVC.htmlStr = self.goodsDetailDict[@"about"];
        ImageTxtVC.title = @"图文详情";
        [self.navigationController pushForm:self.navigationController pushToAndHidden:ImageTxtVC];
        
    }
    
}



- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return HEIGHT/2;
    }else if(section == 1){
        return 0.01;
    }else{
        return 5;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return 0.01;
    }else if (indexPath.section ==1){
        
        if (iPhone5) {
            return HEIGHT/4.5;
        }else if(iPhone6){
            return HEIGHT/5.5+5;
        }else{
            return HEIGHT/5.8+5;
        }
    }else if(indexPath.section ==2){
        
        //0 为无优惠活动
        if ([self.goodsDetailDict[@"is_show_inter_money"] isEqual:@(0)]) {
            return 0.01;
        }else{
            return HEIGHT/15;
        }
        
    }else{
        
        return HEIGHT/15;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        
        NSMutableArray *imageArr = [NSMutableArray array];
        for (int i = 0; i < _cycleArray.count; ++i) {
            NSString *str = [NSString stringWithFormat:@"%@",_cycleArray[i]];
            [imageArr addObject:str];
        }
                NSLog(@"%@",imageArr);
        
        
        
        _XrCarouselView = [XRCarouselView carouselViewWithFrame:CGRectMake(0,0, WIDTH, HEIGHT/2) imageArray:imageArr];
        _XrCarouselView.time = 2;
        [_XrCarouselView setPageColor:[UIColor whiteColor] andCurrentPageColor:DEFAULT_COLOR];
        return _XrCarouselView;
    }
    return nil;
}


@end
